<?php
// /src/model/database.php
// REQUIRE:
if(version_compare(PHP_VERSION, '5.3.0', '>=')) { require_once __DIR__.'/../include.inc'; } 
else { require_once dirname(__FILE__).'/../include.inc'; }

class Database
{
	protected static $hostname = HOSTNAME;
	protected static $database = DATABASE;
	protected static $username = USERNAME;
	protected static $password = PASSWORD;
	
	private static $result;
	private static $link = null;
	
	private static function connect() 
	{
		self::$link = new PDO("mysql:host=".self::$hostname.";dbname=".self::$database."", self::$username, self::$password);
	}
	
	public static function get()
	{
		if(self::$link == null)
			self::connect();
			
		return self::$link;
	}
	
	public static function query($q)
	{
		if(self::$link == null)
			self::connect();
		
		return self::get()->query($q);
	}
	
	
	
	public function __construct($hostname, $database, $username, $password)
	{
		$this->__initialize($hostname, $database, $username, $password);
	}
	
	public function __initialize($hostname, $database, $username, $password)
	{
		$this->connection = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);
		$this->hostname = $hostname;
		$this->database = $database;
		$this->username = $username;
		$this->password = $password;
	}
	

}
?>